package com.ruoyi.web.controller.project;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.dgy.project.domain.ProjectPlan;
import com.dgy.project.service.IProjectPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预期研究成果Controller
 *
 * @author ccc
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/project/plan")
public class ProjectPlanController extends BaseController
{
    @Autowired
    private IProjectPlanService projectPlanService;

    /**
     * 查询预期研究成果列表
     */
    @PreAuthorize("@ss.hasPermi('project:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectPlan projectPlan)
    {
        startPage();
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        return getDataTable(list);
    }

    /**
     * 导出预期研究成果列表
     */
    @PreAuthorize("@ss.hasPermi('project:plan:export')")
    @Log(title = "预期研究成果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectPlan projectPlan)
    {
        List<ProjectPlan> list = projectPlanService.selectProjectPlanList(projectPlan);
        ExcelUtil<ProjectPlan> util = new ExcelUtil<ProjectPlan>(ProjectPlan.class);
        util.exportExcel(response, list, "预期研究成果数据");
    }

    /**
     * 获取预期研究成果详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectPlanService.selectProjectPlanById(id));
    }

    /**
     * 新增预期研究成果
     */
    @PreAuthorize("@ss.hasPermi('project:plan:add')")
    @Log(title = "预期研究成果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.insertProjectPlan(projectPlan));
    }

    /**
     * 修改预期研究成果
     */
    @PreAuthorize("@ss.hasPermi('project:plan:edit')")
    @Log(title = "预期研究成果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectPlan projectPlan)
    {
        return toAjax(projectPlanService.updateProjectPlan(projectPlan));
    }

    /**
     * 删除预期研究成果
     */
    @PreAuthorize("@ss.hasPermi('project:plan:remove')")
    @Log(title = "预期研究成果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectPlanService.deleteProjectPlanByIds(ids));
    }
}
